package brc.symbolTable;

import brc.syntacticTree.TypedTreeNode;

public class SymbolEntry {
	private String symbol;
	private transient boolean referenced; 
	private int type;
	private int ref;
	
	SymbolEntry(String symbol, int type) {
		this(symbol, type, SymbolEntry.getNextReference(type));
	}
	private SymbolEntry(String symbol, int type, int ref) {
		if (symbol == null) {
			throw new NullPointerException();
		}
		this.symbol = symbol;
		this.type = type;
		this.ref = ref;
		this.referenced = false;
	}
	
	public String getSymbol() {
		return symbol;
	}
	public int getType() {
		return type;
	}
	public int getRef() {
		return ref;
	}
	public boolean isReferenced() {
		return referenced;
	}
	public void setReferenced(boolean referenced) {
		this.referenced = referenced;
	}

	private static int globalReference = 1;
	private static int getNextReference(int type) {
		int ref = SymbolEntry.globalReference;
		
		switch (type) {
		case TypedTreeNode.TIPO_NUMERO:
			SymbolEntry.globalReference += 2;
			break;
		case TypedTreeNode.TIPO_TEXTO:
			SymbolEntry.globalReference++;
			break;
		default:
			throw new IllegalArgumentException("Unknown type passed as parameter");
		}
		
		return ref;
	}
}
